package com.kgc.service.impl;

import com.kgc.dao.DiscountMapper;
import com.kgc.pojo.Discount;
import com.kgc.pojo.DiscountExample;
import com.kgc.service.DiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiscountServiceImpl implements DiscountService {
    @Autowired
    DiscountMapper discountMapper;
    //@Cacheable(value = "discount",key = "'getDiscountInfoList'+#statusId+','+#userId")
    @Override
    public List<Discount> getDiscountInfoList(Integer statusId, Integer userId) {
        DiscountExample discountExample = new DiscountExample();
        DiscountExample.Criteria criteria = discountExample.createCriteria();
        if (statusId != null){
            criteria.andStatusidEqualTo(statusId);
        }
        if (userId != null){
            criteria.andUseridEqualTo(userId);
        }
        return discountMapper.selectByExample(discountExample);
    }

    @Override
    public List<Discount> addDiscount(String discountNum) {
        DiscountExample discountExample = new DiscountExample();
        DiscountExample.Criteria criteria = discountExample.createCriteria();
        if (discountNum!= null){
            criteria.andDiscountnumEqualTo(discountNum);
        }
        return discountMapper.selectByExample(discountExample);
    }
}
